﻿
#include "FITKSEASubSysShellPlate.h"
#include "FITKAcousticsDiscModel.h"
#include "FITKAcousticsSEAModel.h"
#include "FITKAcousticsDiscNodeList.h"
#include "FITKAbstractSEAFace.h"
#include "FITKAcousticsTriangles.h"
#include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h"
#include "FITK_Kernel/FITKAppFramework/FITKGlobalData.h"
#include "FITK_Interface/FITKInterfaceModel/FITKElementFactory.h"
#include "FITK_Interface/FITKInterfaceModel/FITKElementTri.h"
#include "FITK_Component/FITK2DMeshTools/FITKTriMeshGenEarCut.h"

namespace Acoustics
{
    FITKAbstractSEASubSys::SEASubSysType Acoustics::FITKSEASubSysPlateShell::getSEASubSysType()
    {
        return FITKAbstractSEASubSys::SEASubSysType::SEAFlatPlate;
    }

    bool FITKSEASubSysPlateShell::updateTriMesh()
    {
        //获取离散数据
        Acoustics::FITKAcousticsDiscModel* discModel = FITKAPP->getGlobalData()->getMeshData<Acoustics::FITKAcousticsDiscModel>();
        if (!discModel)return false;
        //获取节点管理器
        Acoustics::FITKAcousticsDiscNodeList* discNodesList = discModel->getNodes();
        if (!discNodesList)return false;

        auto nodes = this->getNodes();
        auto triMesh = this->getTriangleMesh();
        if (nodes.isEmpty() || triMesh == nullptr) return false;

        //获取点数据
        QList<Core::FITKNode*> nodesList;
        for (QList<Acoustics::FITKAbstractSEASubSysWithNodes::SubSysNode>::iterator iter = nodes.begin(); iter != nodes.end(); ++iter)
        {
            Core::FITKNode* node = discNodesList->getNodeByID(iter->_id);
            if (!node)continue;
            nodesList.append(node);
        }
        if (nodesList.isEmpty()) return false;
        //平板三角单元生成
        Interface::FITKTriMeshGenEarCut triMeshGen;
        triMeshGen.setPointList(nodesList);
        if (!triMeshGen.generateMesh())return false;
        QList<Interface::FITKAbstractElement*> elementList = triMeshGen.getTriangle();
        for (Interface::FITKAbstractElement* elem : elementList)
            triMesh->appendElement(elem);
        return true;
    }
}


